\section{Basic Customizations}

In this video, we're going to look a little bit more closely at different ways we can customize \LaTeX{} documents. Specifically, we're going to look at some of the large-scale features of \LaTeX{} documents and see how to manipulate them.

\begin{center}
  \fbox{\includegraphics[width=0.5\linewidth]{img-7-1}}
\end{center}

One of the things that we need to talk about is the paper size. Depending on your system, your default paper size may be A4 or it may be letter size. The two paper sizes are actually slightly different, with letter size paper being common in North America and A4 paper being common pretty much everywhere else. The differences are small enough that for basic applications like homework assignments, there is no practical difference.

\begin{center}
  \fbox{\includegraphics[width=0.95\linewidth]{img-7-2}}
\end{center}

If you wanted to change the paper size, you could do it as an optional parameter for the document class. But this can also be done with the \href{https://ctan.org/pkg/geometry}{\texttt{geometry}} package, which also has a much more robust collection of paper sizes to choose from. You can even create a custom paper size if you wanted by setting the \verb|paperwidth| and \verb|paperheight| values as optional parameters. This is also convenient because we can do more with the \href{https://ctan.org/pkg/geometry}{\texttt{geometry}} package.

\begin{center}
  \fbox{\includegraphics[width=0.95\linewidth]{img-7-3}}
\end{center}

Previously, we had defined all of the margins to be the same. But the \href{https://ctan.org/pkg/geometry}{\texttt{geometry}} package lets you specify each margin separately if you wanted. There are actually many more parameters that you can specify using the \href{https://ctan.org/pkg/geometry}{\texttt{geometry}} package, and it's a good starting point if you want to start understanding some of the finer details of how \LaTeX{} dimensions work.

\begin{center}
  \fbox{\includegraphics[width=0.95\linewidth]{img-7-4}}
\end{center}

This is a diagram that comes from the documentation. This shows you the construction of the page layout and the dimensions that the package uses to do it. But we will leave things here for this video.

\begin{center}
  \fbox{\includegraphics[width=0.75\linewidth]{img-7-5}}
\end{center}

If you wanted to have your paper oriented as landscape instead of portrait, you can use the landscape option with the geometry package. The downside of this is that it makes the entire document in landscape mode. If you only wanted parts of the document to be this way, \href{https://ctan.org/pkg/pdflscape}{\texttt{pdflscape}} can do this. Just put the parts you want in landscape mode between \verb|\begin{landscape}| and \verb|\end{landscape}|. This can be helpful if you have a wide table or image that needs the extra width.

\begin{center}
  \fbox{\includegraphics[width=0.65\linewidth]{img-7-6}}
\end{center}

Another useful package for customizing your document is the \href{https://ctan.org/pkg/fancyhdr}{\texttt{fancyhdr}} package. If you use the \texttt{fancy} pagestyle, you will get a line across the top and the bottom of the page. This also creates six different regions that you can put text into. This text will persist across all the pages. The three top regions can be specified by defining the \texttt{fancyhead} and indicating whether you want to change the left, center, or right part. The bottom is done in the same way except that you change the \texttt{fancyfoot}. You can use this to set up a generic template for your homework assignments so that they have a consistent look and feel to them.

\begin{center}
  \fbox{\includegraphics[width=0.95\linewidth]{img-7-7}}
\end{center}

To print the page number, use the command \verb|\thepage|. The value of \verb|\thepage| starts at 1 and increases every time \LaTeX{} goes through the process of creating a new page. Technically, the counter name is \texttt{page} and the command \verb|\thepage| is just the command that causes the value of \texttt{page} to be printed.

If you want your page counter to also indicate the total number of pages in the document, you will need to add in another package. There are several options for this, but the \href{https://ctan.org/pkg/lastpage}{\texttt{lastpage}} package is the most commonly recommended. All you do to reference the total number of pages is use \verb|\pageref{LastPage}|. Sometimes you will get question marks or the wrong number of pages when you do this. This is because \LaTeX{} won't know how many pages there are until after it builds the document. Compiling it a second time should fix the issue.

You will notice that in the code for the footer, there's a backslash followed by a space after \verb|\thepage|. What that extra backslash does is explicitly tell \LaTeX{} that you want a space after displaying the value. This can also be done with curly brackets, but I think it's more common in this context to use the backslash.

\begin{center}
  \fbox{\includegraphics[width=0.85\linewidth]{img-7-8}}
\end{center}

Speaking of pages, if you wanted to force \LaTeX{} to start a new page, you can use either the \verb|\newpage| or the \verb|\pagebreak| command. The difference between these two is that \verb|\pagebreak| will stretch out the vertical spacing so that the text fills the page, whereas the \verb|\newpage| command will push all the whitespace to the bottom. In other words, \verb|\pagebreak| is a soft page break that tries to keep the flow and continuity of the text and \verb|\newpage| creates a hard stop.

\begin{center}
  \fbox{\includegraphics[width=0.95\linewidth]{img-7-9}}
\end{center}

One final customization that is often useful is the creation of new commands. These new commands are often useful for symbols and notation that can sometimes become a bit annoying to type out. For example, in real analysis you may eventually get tired of having to write \verb|\mathbb{R}| to get the symbol for the real numbers. To create a new command, you simply put \verb|\newcommand{}{}| into the preamble. The first bracket names the command and second is the command you want it to execute. I use \verb|\R| for the real numbers, but some people use \verb|\RR|. Either way, the use of \verb|\newcommand| creates a shortcut that significantly reduces the amount of typing that's required and can sometimes make your code easier to read.

If the command already exists, you can pick a different name or use \verb|\renewcommand{}{}|. But be careful when you do this! You might overwrite a command that is used elsewhere in the document without you realizing it. It's usually safest to just pick a new name.

\begin{center}
  \fbox{\includegraphics[width=0.95\linewidth]{img-7-10}}
\end{center}

You can use \verb|\newcommand| with the \verb|\operatorname| command, but there's another method for declaring functions that you should be aware of. This is the \verb|\DeclareMathOperator{}{}| command. They both do the same thing, but you'll probably see \verb|\DeclareMathOperator| more frequently on \TeX\ Stack Exchange. It's worth pointing out that there's a starred version of these commands which changes the behavior of superscripts and subscripts. When you're in display style math mode, instead of being printed to the right the starred versions will typeset them directly above and below.

The downside of these customized commands is that other people will have problems processing the text unless they also have all of the new commands that you've created. When transferring whole documents, this isn't a problem. But if you're emailing someone a small chunk of text, this can sometimes create unexpected errors. Fortunately, you can just tell them what the shortcuts do and they should be able to fix it.

These customizations should go a long way in helping you set up \LaTeX{} to suit your specific needs.